package com.itheima.tlias.tliasweb.controller;

import com.itheima.tlias.tliasweb.pojo.Result;
import com.itheima.tlias.tliasweb.pojo.UserLoginDTO;
import com.itheima.tlias.tliasweb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {

    @Autowired
    private UserService userService;

    /**
     * 用户登录
     * */
    @PostMapping("/login")
    public Result login(@RequestBody UserLoginDTO dto){
        String token = userService.login(dto);
        if(StringUtils.hasLength(token)){
            return Result.success(token);
        }else{
            return Result.error("用户名或者密码错误");
        }
    }
}
